package com.foreveross.framework.example.tags.converter;

import com.foreveross.framework.example.tags.domain.City;
import org.springframework.core.convert.converter.Converter;

public class StringToCityConverter implements Converter<String, City> {

  @Override
  public City convert(String source) {
    if ("gz".equals(source)) {
      return new City("广州", "gz");
    } else if ("sz".equals(source)) {
      return new City("深圳", "sz");
    } else if ("zh".equals(source)) {
      return new City("珠海", "zh");
    }

    throw new IllegalArgumentException("No such city. " + source);
  }

}
